<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        #box {
            width: 100px;
            height: 100px;
            background: red
        }

        #box2 {
            width: 100px;
            height: 100px;
            background: green
        }

        #box3 {
            width: 100px;
            height: 100px;
            background: blue
        }

    </style>
</head>
<body>
    <div id="box"></div>
    <div id="box2"></div>
    <div id="box3"></div>
</body>
<script>
    var box = document.getElementById("box")
    var box2 = document.getElementById("box2")
    var box3 = document.getElementById("box3")

    box.onclick = function () {
        alert(1)
    }

    //JS 中函数名后面加与不加括号的区别
    //    box2.onclick = fn2();
    box2.onclick = fn2;

    function fn2() {
        alert(2)

    }

    box3.onclick = function () {
        fn3();
    }

    function fn3() {
        alert(3)
    }


</script>
</html>